package com.peiwan.ranking.controller;

import com.peiwan.ranking.dto.RankingDTO;
import com.peiwan.ranking.service.RankingService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/ranking")
public class RankingController {

    private final RankingService rankingService;

    public RankingController(RankingService rankingService) {
        this.rankingService = rankingService;
    }

    @GetMapping("/companion")
    public ResponseEntity<List<RankingDTO>> getCompanionRanking(
            @RequestParam(required = false) Integer year,
            @RequestParam(required = false) Integer month) {
        try {
            List<RankingDTO> rankings = rankingService.getCompanionRanking(year, month);
            return ResponseEntity.ok(rankings);
        } catch (Exception e) {
            return ResponseEntity.internalServerError().build();
        }
    }

    @GetMapping("/dispatch")
    public ResponseEntity<List<RankingDTO>> getDispatchRanking(
            @RequestParam(required = false) Integer year,
            @RequestParam(required = false) Integer month) {
        try {
            List<RankingDTO> rankings = rankingService.getDispatchRanking(year, month);
            return ResponseEntity.ok(rankings);
        } catch (Exception e) {
            return ResponseEntity.internalServerError().build();
        }
    }

    @GetMapping("/receptionist")
    public ResponseEntity<List<RankingDTO>> getReceptionistRanking(
            @RequestParam(required = false) Integer year,
            @RequestParam(required = false) Integer month) {
        try {
            List<RankingDTO> rankings = rankingService.getReceptionistRanking(year, month);
            return ResponseEntity.ok(rankings);
        } catch (Exception e) {
            return ResponseEntity.internalServerError().build();
        }
    }
} 